package br.unipampa.view;

import br.unipampa.utilitarios.*;
import java.awt.Component;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.*;
import java.util.ArrayList;

public class FormularioPrincipal extends javax.swing.JFrame implements ImplementaIcone {

    private Image iconeTitulo;
    private TrataDataHora dateHora;
    
    public FormularioPrincipal() {
        initComponents();

        revalidate();
        //WINDOWS LISTENER
        addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                ApoioDeInterface.mensagemSair();
            }
        });

        tratarIcone();

        setResizable(false);
        setLocationRelativeTo(null);
        
        //DEFINE A INICIALIZAÇÃO DA TABELA JÀ NA DATA, MES, ANO ATUAL
        this.dateHora= new TrataDataHora();
        ArrayList<Object> objetosDeTempo= this.dateHora.retornaTempoAtual();
        this.paneCompromisso2.initCompromissoDeHoje((String) objetosDeTempo.get(1), 
                (String) objetosDeTempo.get(2), 
                (int) objetosDeTempo.get(0));
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanelTabulado = new javax.swing.JTabbedPane();
        jPanelCompromissos = new javax.swing.JPanel();
        paneCompromisso2 = new br.unipampa.view.PaneCompromisso();
        jPanelTelefones = new javax.swing.JPanel();
        paneTelefones1 = new br.unipampa.view.PaneTelefones();
        jPanelConfig = new javax.swing.JPanel();
        paneConfiguracao1 = new br.unipampa.view.PaneConfiguracao();
        jPanelDadosDoDesenvo = new javax.swing.JPanel();
        jPanelInterDesenvol = new javax.swing.JPanel();
        lblNome = new javax.swing.JLabel();
        lblEmail = new javax.swing.JLabel();
        lblWebSite = new javax.swing.JLabel();
        jPanelIdenUser = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        lblNomeUsuario = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        lblTipoUser = new javax.swing.JLabel();
        jPanelTimer = new javax.swing.JPanel();
        lblTimer = new javax.swing.JLabel();
        lblData = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();

        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
        setTitle("Agenda Universitária");
        setBackground(new java.awt.Color(204, 204, 255));
        setForeground(new java.awt.Color(204, 204, 255));

        jPanelTabulado.setBackground(new java.awt.Color(204, 204, 255));

        jPanelCompromissos.setBackground(new java.awt.Color(204, 204, 255));

        javax.swing.GroupLayout jPanelCompromissosLayout = new javax.swing.GroupLayout(jPanelCompromissos);
        jPanelCompromissos.setLayout(jPanelCompromissosLayout);
        jPanelCompromissosLayout.setHorizontalGroup(
            jPanelCompromissosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelCompromissosLayout.createSequentialGroup()
                .addComponent(paneCompromisso2, javax.swing.GroupLayout.DEFAULT_SIZE, 924, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanelCompromissosLayout.setVerticalGroup(
            jPanelCompromissosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(paneCompromisso2, javax.swing.GroupLayout.DEFAULT_SIZE, 468, Short.MAX_VALUE)
        );

        jPanelTabulado.addTab("Compromissos", jPanelCompromissos);

        jPanelTelefones.setBackground(new java.awt.Color(204, 204, 255));

        javax.swing.GroupLayout jPanelTelefonesLayout = new javax.swing.GroupLayout(jPanelTelefones);
        jPanelTelefones.setLayout(jPanelTelefonesLayout);
        jPanelTelefonesLayout.setHorizontalGroup(
            jPanelTelefonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTelefonesLayout.createSequentialGroup()
                .addComponent(paneTelefones1, javax.swing.GroupLayout.PREFERRED_SIZE, 742, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 194, Short.MAX_VALUE))
        );
        jPanelTelefonesLayout.setVerticalGroup(
            jPanelTelefonesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTelefonesLayout.createSequentialGroup()
                .addComponent(paneTelefones1, javax.swing.GroupLayout.PREFERRED_SIZE, 467, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 1, Short.MAX_VALUE))
        );

        jPanelTabulado.addTab("Telefones", jPanelTelefones);

        jPanelConfig.setBackground(new java.awt.Color(204, 204, 255));

        javax.swing.GroupLayout jPanelConfigLayout = new javax.swing.GroupLayout(jPanelConfig);
        jPanelConfig.setLayout(jPanelConfigLayout);
        jPanelConfigLayout.setHorizontalGroup(
            jPanelConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelConfigLayout.createSequentialGroup()
                .addComponent(paneConfiguracao1, javax.swing.GroupLayout.DEFAULT_SIZE, 924, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanelConfigLayout.setVerticalGroup(
            jPanelConfigLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelConfigLayout.createSequentialGroup()
                .addComponent(paneConfiguracao1, javax.swing.GroupLayout.PREFERRED_SIZE, 464, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 4, Short.MAX_VALUE))
        );

        jPanelTabulado.addTab("Configurações", jPanelConfig);

        jPanelDadosDoDesenvo.setBackground(new java.awt.Color(204, 204, 255));

        jPanelInterDesenvol.setBackground(new java.awt.Color(204, 204, 255));
        jPanelInterDesenvol.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dados", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 0, 14), java.awt.Color.darkGray)); // NOI18N

        lblNome.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lblNome.setText("Nome: Gabriel Bronzatti Moro");

        lblEmail.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lblEmail.setText("Email: gabrielmoro@alunos.unipampa.edu.br");

        lblWebSite.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        lblWebSite.setText("WebSite: https://sites.google.com/site/gabrielbronzattimoro/");

        javax.swing.GroupLayout jPanelInterDesenvolLayout = new javax.swing.GroupLayout(jPanelInterDesenvol);
        jPanelInterDesenvol.setLayout(jPanelInterDesenvolLayout);
        jPanelInterDesenvolLayout.setHorizontalGroup(
            jPanelInterDesenvolLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelInterDesenvolLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelInterDesenvolLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lblNome)
                    .addComponent(lblWebSite, javax.swing.GroupLayout.PREFERRED_SIZE, 485, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(lblEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 367, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(155, Short.MAX_VALUE))
        );
        jPanelInterDesenvolLayout.setVerticalGroup(
            jPanelInterDesenvolLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelInterDesenvolLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lblNome)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblEmail)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(lblWebSite)
                .addContainerGap(61, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanelDadosDoDesenvoLayout = new javax.swing.GroupLayout(jPanelDadosDoDesenvo);
        jPanelDadosDoDesenvo.setLayout(jPanelDadosDoDesenvoLayout);
        jPanelDadosDoDesenvoLayout.setHorizontalGroup(
            jPanelDadosDoDesenvoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDadosDoDesenvoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelInterDesenvol, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(262, Short.MAX_VALUE))
        );
        jPanelDadosDoDesenvoLayout.setVerticalGroup(
            jPanelDadosDoDesenvoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDadosDoDesenvoLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanelInterDesenvol, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(296, Short.MAX_VALUE))
        );

        jPanelTabulado.addTab("Dúvidas", jPanelDadosDoDesenvo);

        jPanelIdenUser.setBackground(new java.awt.Color(51, 51, 51));
        jPanelIdenUser.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Identificação de Usuário", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 0, 12), java.awt.Color.white)); // NOI18N

        jLabel4.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Usuário:");

        lblNomeUsuario.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        lblNomeUsuario.setForeground(new java.awt.Color(255, 255, 255));
        lblNomeUsuario.setText("<nomeUsuario>");

        jLabel5.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(255, 255, 255));
        jLabel5.setText("Tipo de Usuário:");

        lblTipoUser.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        lblTipoUser.setForeground(new java.awt.Color(255, 255, 255));
        lblTipoUser.setText("<tipoDeUsuario>");

        javax.swing.GroupLayout jPanelIdenUserLayout = new javax.swing.GroupLayout(jPanelIdenUser);
        jPanelIdenUser.setLayout(jPanelIdenUserLayout);
        jPanelIdenUserLayout.setHorizontalGroup(
            jPanelIdenUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelIdenUserLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelIdenUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelIdenUserLayout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(lblNomeUsuario))
                    .addGroup(jPanelIdenUserLayout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(lblTipoUser)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelIdenUserLayout.setVerticalGroup(
            jPanelIdenUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelIdenUserLayout.createSequentialGroup()
                .addGroup(jPanelIdenUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(lblNomeUsuario))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanelIdenUserLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(lblTipoUser))
                .addContainerGap())
        );

        jPanelTimer.setBackground(new java.awt.Color(51, 51, 51));
        jPanelTimer.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Hora e Data", javax.swing.border.TitledBorder.CENTER, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 0, 12), java.awt.Color.white)); // NOI18N

        lblTimer.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        lblTimer.setForeground(new java.awt.Color(255, 255, 255));
        lblTimer.setText("<timer>");

        lblData.setFont(new java.awt.Font("Arial", 0, 14)); // NOI18N
        lblData.setForeground(new java.awt.Color(255, 255, 255));
        lblData.setText("dd/mm/aaaa");

        javax.swing.GroupLayout jPanelTimerLayout = new javax.swing.GroupLayout(jPanelTimer);
        jPanelTimer.setLayout(jPanelTimerLayout);
        jPanelTimerLayout.setHorizontalGroup(
            jPanelTimerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(lblTimer, javax.swing.GroupLayout.DEFAULT_SIZE, 197, Short.MAX_VALUE)
            .addGroup(jPanelTimerLayout.createSequentialGroup()
                .addComponent(lblData, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
        );
        jPanelTimerLayout.setVerticalGroup(
            jPanelTimerLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelTimerLayout.createSequentialGroup()
                .addComponent(lblTimer)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(lblData)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        jSeparator1.setForeground(new java.awt.Color(204, 204, 204));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jSeparator1)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanelTimer, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanelIdenUser, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jPanelTabulado))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jPanelTabulado)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 5, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanelIdenUser, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanelTimer, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanelCompromissos;
    private javax.swing.JPanel jPanelConfig;
    private javax.swing.JPanel jPanelDadosDoDesenvo;
    private javax.swing.JPanel jPanelIdenUser;
    private javax.swing.JPanel jPanelInterDesenvol;
    private javax.swing.JTabbedPane jPanelTabulado;
    private javax.swing.JPanel jPanelTelefones;
    private javax.swing.JPanel jPanelTimer;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel lblData;
    private javax.swing.JLabel lblEmail;
    private javax.swing.JLabel lblNome;
    private javax.swing.JLabel lblNomeUsuario;
    private javax.swing.JLabel lblTimer;
    private javax.swing.JLabel lblTipoUser;
    private javax.swing.JLabel lblWebSite;
    private br.unipampa.view.PaneCompromisso paneCompromisso2;
    private br.unipampa.view.PaneConfiguracao paneConfiguracao1;
    private br.unipampa.view.PaneTelefones paneTelefones1;
    // End of variables declaration//GEN-END:variables

    public void ativarModulosComCredenciais(TipoDeUsuario tipo, String nome) {
        lblNomeUsuario.setText(nome);
        if (tipo == TipoDeUsuario.COMUM) {
            for (Component c : paneConfiguracao1.getComponents()) {
                c.setEnabled(false);
            }
            for (Component c : paneConfiguracao1.getjPanelAcoes2().getComponents()) {
                c.setEnabled(false);
            }
            
            lblTipoUser.setText("Comum");
            jPanelIdenUser.revalidate();
        } else {
            lblTipoUser.setText("Administrador");
            jPanelIdenUser.revalidate();
        }
        setVisible(true);
    }

    public void atualizaPanelTimer(String txtHora, String data) {
        this.lblTimer.setText(txtHora);
        this.lblData.setText(data);
        this.jPanelTimer.revalidate();
    }

    /**
     * @return the jPanelIdenUser
     */
    public javax.swing.JPanel getjPanelIdenUser() {
        return jPanelIdenUser;
    }

    public void definirNomeDeUser(String nome) {
        this.paneConfiguracao1.nomeUsuario = nome;
    }

    @Override
    public void tratarIcone() {
        //definindo icone do sistema
        this.iconeTitulo = Toolkit.getDefaultToolkit().getImage(
                getClass().getResource("/br/unipampa/icons/iconeOfSystem.png"));

        this.setIconImage(this.iconeTitulo);
    }
}
